package com.wang.utils;

import javafx.util.Pair;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author wr
 * @date 2021/10/28 15:36
 */
public class FileManager {
    private static final String ROOT_PATH = "./storage/";

    public static List<Pair<String, Boolean>> getAllByUser(String path) {
        String realPath = ROOT_PATH + path;
        File file = new File(realPath);
        List<Pair<String, Boolean>> res = new ArrayList<>();
        if (file.exists() && file.isDirectory()) {
            for (File f : Objects.requireNonNull(file.listFiles())) {
                res.add(new Pair<>(f.getName(), f.isDirectory()));
            }
        }
        return res;
    }

    public static boolean createUserDir(String user) {
        File file = new File(ROOT_PATH + user);
        if(file.exists()){
            return true;
        }else {
            return file.mkdir();
        }
    }

    public static void main(String[] args) {
        List<Pair<String, Boolean>> allByPath = FileManager.getAllByUser("");
        System.out.println(allByPath.toString());
    }
}
